package com.auerdi.ui.fragment.a_home.adapter.delegate;

import android.view.View;
import android.widget.ImageView;

import com.auerdi.R;
import com.auerdi.ui.detail.cutprice.ADCutHomeFragMent;
import com.auerdi.ui.detail.sho.ADTwoShowFragMent;
import com.auerdi.ui.detail.sho.ADTwoShowFragMentB;
import com.auerdi.ui.detail.sho.ADTwoShowFragMentC;
import com.auerdi.ui.fragment.a_home.adapter.items.HomeItemsBean;
import com.example.egghttp.retrofit.beans.banner.HomeBanner;
import com.squareup.picasso.Picasso;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by zhy on 16/6/22.
 */
public class BisAct implements ItemViewDelegate<HomeItemsBean> {

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_home_b_act;
    }

    @Override
    public boolean isForViewType(HomeItemsBean item, int position) {

//        item.getRouter()

        return item.getRouter().equals(getClass().getSimpleName());
    }

    @Override
    public void convert(ViewHolder holder, HomeItemsBean item, int position) {


        ImageView imgA = holder.getView(R.id.img_a);
        ImageView imgB = holder.getView(R.id.img_b);
        ImageView imgC = holder.getView(R.id.img_c);
        ImageView imgD = holder.getView(R.id.img_d);

        List<HomeBanner> banners = (List<HomeBanner>) item.getItem();

        Picasso.get().load(banners.get(0).getImg()).error(R.mipmap.logo).placeholder(R.mipmap.logo).fit().centerInside().into(imgA);
        Picasso.get().load(banners.get(1).getImg()).error(R.mipmap.logo).placeholder(R.mipmap.logo).fit().centerCrop().into(imgB);
        Picasso.get().load(banners.get(2).getImg()).error(R.mipmap.logo).placeholder(R.mipmap.logo).fit().centerInside().into(imgC);
        Picasso.get().load(banners.get(3).getImg()).error(R.mipmap.logo).placeholder(R.mipmap.logo).fit().centerInside().into(imgD);

        imgA.setOnClickListener(v -> EventBus.getDefault().post(new ADTwoShowFragMent()));

        imgB.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new ADTwoShowFragMentB());
            }
        });
        imgC.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new ADCutHomeFragMent());
            }
        });
        imgD.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new ADTwoShowFragMentC());
            }
        });
    }
}
